<template>
	<ul class="news item" v-infinite-scroll="loadMore" infinite-scroll-disabled="busy" infinite-scroll-distance="10">
		<router-link v-for="news of newsData" :to="{path:'newsdetail',query:{ id:news.id,columnId:columnId}}" tag="li">
			<h3>{{news.title}}</h3>
			<div class="con">
				<img :src="news.attachmentUrl"/>
				{{news.describes}}
			</div>
			<footer class="footer clearFix">
				<span class="tip"><i class="icon_mark"></i>{{news.typeName}}</span>
				<span class="time"><i class="ion ion-android-time"></i>{{news.releaseDate}}</span>
			</footer>
		</router-link>
		<loading v-if="loadShow"></loading>
		<li class="no_data" v-if="hasNoData">
			<i class="ion ion-ios-paper-outline"></i>
			<p>暂无数据</p>
		</li>
	</ul>
</template>
<script type="text/javascript">

	import getInterface from '../../assets/js/insterface'
	import http from '../../assets/js/http_mixin'

	export default{
		data(){
			return{
				columnId:this.$route.query.columnId,
				busy: false,
				count:0,
				pageTotal:'',
				newsData:[],
				hasNoData:false,
				newsUrl:getInterface.getNewsListUrl
			}
		},
		mixins:[http],
		mounted(){
			this.$el.parentElement.parentNode.style.background = '#fafafa';
			let columnId = this.$route.query.columnId;
			switch(columnId){
				case '56':
					document.title="周报";
					break;
				case '57':
					document.title="重要政策";
					break;
				case '58':
					document.title="重要新闻";
					break;
				case '59':
					document.title="问卷调查";
					break;
				case '60':
					document.title="在线培训";
					break;
			}
			this.getNewsData();
		},
		methods:{
			loadMore(){
				let vue = this;
			      this.busy = true;
			      if(this.pageTotal > this.count && this.newsData.length > 0){
				      setTimeout(() => {
				        vue.getNewsData();
				      }, 1000);
			      }
			},
			getNewsData(){
				let params = {
					'pageSize':'10',//每页显示的数目
					'currentPage':this.count,
					'columnId':this.$route.query.columnId
				};
				this.$http.post(this.newsUrl,params,{emulateJSON: true})
				.then((response) =>{
					console.log(response);
					if(response.data.resType == '00'){
						let responseData = response.data.data;
						let resDataLen = responseData.length;
						this.pageTotal = response.data.pages;

						if(resDataLen > 0){
							this.hasNoData = false;

							if(this.pageTotal > this.count){
								for(let i=0; i < resDataLen; i++){
									this.newsData.push(responseData[i])
								}
								this.count++;
							}
						}else{
							this.hasNoData= true;
						}
						this.busy = false;
					}else{
						console.log(response.data.msg);

					}
				})
			}
		}

	}
</script>